﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DelegateDemo01
{
    internal class Program
    {
        static void Main(string[] args)
        {
            TestAction(5, ActionFuc);
            int[] ints = { 1, 2, 3, 10, 6, 4, 9 };
            Sort(ints);

            RecipeRepository recipeRepository = new RecipeRepository();
            recipeRepository.AddRecipe(10, FucFuc);
            Console.ReadKey();
        }

        static void Sort(int[] sortArray)
        {
            Func = Compare;
            for (int i = 0; i < sortArray.Length; i++)
            {
                for (int j = 0; j < sortArray.Length; j++)
                {
                    if (Func(sortArray[i],sortArray[j]))
                    {
                        int temp = 0; 
                        temp = sortArray[i];
                        sortArray[i] = sortArray[j];
                        sortArray[j] = temp;
                    }
                }
            }
        }

        static bool Compare(int a ,int b)
        {
            return a > b;
        }

        static Func<int, int, bool> Func;


        static Action<int> Action;

        static void TestAction(int a,Action<int> action)
        {
            action(a);            
        }

        static void ActionFuc(int a)
        {
            Console.WriteLine($"Hello world {a}");
        }   

        static bool FucFuc(int a)
        {
            Console.WriteLine($"Hello world {a}");
            return true;
        }   
    }

    public class RecipeRepository
    {
        public delegate void RecipeEventHandler(Recipe recipe);

        public event RecipeEventHandler RecipeAdded;

        public void AddRecipe(int recipeId,Func<int,bool> action)
        {
            bool state = action(recipeId);
        }
    }

    public class Recipe
    {
        public string Name { get; set; }
        public string Description { get; set; }
    }
}
